/*
 * TestIndex.cpp
 *
 *      Author: carlos
 */

#include "TestIndex.h"
#include "../../src/logical_layer/index/BPlussIStructureFactory.h"
#include "../../src/logical_layer/EntityFactory.h"
#include <assert.h>
TestIndex::TestIndex() {

}

void TestIndex::run() {
	testCreacionIStructure();
	testSimpleSecondaryIndex();
	testSimpleStringSecondaryIndex();
}

TestIndex::~TestIndex() {
}

void TestIndex::testCreacionIStructure() {
	//eliminamos los archivos

	cout << "=======iniciando IStrutureBTreeImpl bplus==========" << endl;
	try {
		IStrutureBTreeImpl* index =
				(IStrutureBTreeImpl*) BPlussIStructureFactory::createIStrcutre(
						SIMPLE_SECONDARY_INDEX);
		SimpleSecondaryIndex* ssIndex =
				EntityFactory::createSimpleSecondaryIndex(
						SIMPLE_SECONDARY_INDEX);
		ssIndex->setID(20140130);
		index->insert(ssIndex);
		delete ssIndex;

		SimpleSecondaryIndex* ientidad = (SimpleSecondaryIndex*) index->find(
				"20140130");
		ientidad->agregarIdOrdenado(4);
		ientidad->agregarIdOrdenado(9);
		ientidad->agregarIdOrdenado(34);
		cout << ientidad->toString() << endl;

		index->dropStructure();
		delete index;
	} catch (ProgramException& e) {
		assert(-1);
	}
	cout << "Finalizacion exitosa testCreadionIstrucutre bplus" << endl;
}

void TestIndex::testSimpleSecondaryIndex() {
	cout << "INICIO testSimpleSecondaryIndex bplus" << endl;

	IStrutureBTreeImpl* index = fileHandler->getFechaAscIdTwit();
	SimpleSecondaryIndex* ssIndex =
			(SimpleSecondaryIndex*) EntityFactory::createSimpleSecondaryIndex(
					FECHAASC_IDTWEET);
	ssIndex->setID(3);
	ssIndex->agregarIdOrdenado(1);
	ssIndex->agregarIdOrdenado(2);
	ssIndex->agregarIdOrdenado(3);
	index->insert(ssIndex);
	SimpleSecondaryIndex* ssIndexFound = (SimpleSecondaryIndex*) index->find(
			"3");
	cout << ssIndexFound->toString() << endl;
	index->dropStructure();
	delete index;
	cout << "Finalizacion exitosa testSimpleSecondaryIndex bplus" << endl;

}
void TestIndex::testSimpleStringSecondaryIndex() {
	cout << "INICIO testSimpleStringSecondaryIndex bplus" << endl;
	IStrutureBTreeImpl* index = fileHandler->getTituloIdRss();
	SimpleStringSecondaryindex* ssIndex =
			(SimpleStringSecondaryindex*) EntityFactory::createSimpleStringSecondaryIndex(
					TITULO_IDRSS);
	//ssIndex->setID(3);
	ssIndex->setIdstring("CARLOS");
	ssIndex->agregarIdOrdenado(1);
	ssIndex->agregarIdOrdenado(2);
	ssIndex->agregarIdOrdenado(3);
	index->insert(ssIndex);
	SimpleStringSecondaryindex* ssIndexFound =
			(SimpleStringSecondaryindex*) index->find("CARLOS");
	cout << ssIndexFound->toString() << endl;
	cout << "Finalizacion exitosa testSimpleStringSecondaryIndex bplus" << endl;

	//index->dropStructure();

}

void TestIndex::setFileHandler(FileHandler* fileHandler) {
	this->fileHandler = fileHandler;
}

